package com.sk.ccflower.server.lib.dbUtils.qry;

import java.sql.SQLException;
import java.util.ArrayList;

import com.sk.ccflower.server.lib.dbBeans.MfMatchBean;
import com.sk.ccflower.server.lib.dbUtils.DBConnection;
import com.sk.ccflower.server.lib.dbUtils.SQLReturn;
import com.sk.ccflower.server.lib.dbUtils.SQLRunner;
import com.sk.ccflower.server.lib.dbUtils.sql.MfMatchSql;

public class MfMatchQry extends MfMatchSql {
	
	protected DBConnection m_db = null;
	protected SQLRunner m_sqlRun = null;
	
	public MfMatchQry() throws Exception {
		super();
	}
	
	public MfMatchQry(DBConnection _db) throws Exception {
        m_db = _db;
        m_sqlRun = new SQLRunner();
    }
	
	private int executeQuery(SQLReturn arg) throws SQLException, Exception {
        ArrayList<Object> arr = null;
        
        m_sqlRun.begin(m_db.getConnection(), false);
        arr = m_sqlRun.executeQuery(arg.m_query, arg.m_params, arg.m_class);
        m_sqlRun.end();
        
        int n = put(arr);
        
        return n;
    }
	
	public int select( String email ) throws SQLException, Exception {
		return executeQuery( getSql(email) );
	}
	
	public void insert( MfMatchBean bean ) throws SQLException, Exception {
		try {
			SQLReturn arg = getSqlInsert(bean);

			m_sqlRun.begin(m_db.getConnection(), false);
			m_sqlRun.executeInsert(arg.m_query, bean, arg.m_colMap);
            
            m_sqlRun.commit();
        } catch (SQLException e) {
            m_sqlRun.rollback();
            m_log.error(e.toString(), e);
            throw e;
        } catch (Exception e) {
            m_sqlRun.rollback();
            m_log.error(e.toString(), e);
            throw e;
        } finally {
            m_sqlRun.end();
        }
	}
	
}
